package com.appcenter.message.controller;

import com.appcenter.jz.config.JsonResult;
import com.appcenter.message.input.*;
import com.appcenter.message.service.MessagesService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("api")
@Api("消息操作API")
public class MessageCenterController {
    @Autowired
    MessagesService MsgService;

    @ApiOperation(value = "发送消息", notes = "发送消息",produces = "application/json")
    @PostMapping("/sendMessage")
    public ResponseEntity<JsonResult> sendMessage(@RequestBody SendMessageInput input) throws Exception {
        //throw new ErrorJsonResult("1000001", "捕获异常信息");
        JsonResult r = new JsonResult();
        r.setResult(MsgService.SendMessage(input));
        return ResponseEntity.ok(r);
    }

    @ApiOperation(value = "读取消息", notes = "读取消息",produces = "application/json")
    @PostMapping("/readMessage")
    public ResponseEntity<JsonResult> readMessage(@RequestBody ReadMessageInput input) throws Exception {
        //throw new ErrorJsonResult("1000001", "捕获异常信息");
        JsonResult r = new JsonResult();
        r.setResult(MsgService.ReadMessage(input));
        return ResponseEntity.ok(r);
    }


    @ApiOperation(value = "读取消息个数", notes = "读取消息个数",produces = "application/json")
    @PostMapping("/getUnreadMessageCount")
    public ResponseEntity<JsonResult> getUnreadMessageCount(@RequestBody GetUnreadMessageCountInput input) throws Exception {

        JsonResult r = new JsonResult();
        r.setResult(MsgService.GetUnreadMessageCount(input));
        return ResponseEntity.ok(r);
    }


    @ApiOperation(value = "查询消息信息", notes = "查询消息信息",produces = "application/json")
    @PostMapping("/searchMessageList")
    public ResponseEntity<JsonResult> searchMessageList(@RequestBody SearchMessageListInput input) throws Exception {
        JsonResult r = new JsonResult();
        r.setResult(MsgService.SearchMessageList(input));
        return ResponseEntity.ok(r);
    }


    @ApiOperation(value = "加载消息信息", notes = "加载消息信息",produces = "application/json")
    @PostMapping("/loadManageMessageListPage")
    public ResponseEntity<JsonResult> loadManageMessageListPage(@RequestBody LoadMessageListPageInput input) throws Exception {
        JsonResult r = new JsonResult();
        r.setResult(MsgService.LoadManageMessageListPage(input));
        return ResponseEntity.ok(r);
    }








}
